
	/*if(!isLogined()){
		window.location.href = "index.html";
	}*/
		var userInfor = {};
	/*=============== top start =============*/
		var oTop = document.getElementById("top");
		var aTopSpan = oTop.getElementsByTagName("span");
	/*=============== top end =============*/
	/*=============== main start ==============*/
		var oMain = document.getElementById("main");
		var oMenu = document.getElementById("menu");
		var aMenuLis = oMenu.getElementsByTagName("li");
		var aMenuIcon = getElementsByClass("icon",oMenu);
		var aMenuContent = getElementsByClass("content",oMain);
		var currentLi = 4;
		//初始显示内容
		showContent(0);
		for(var i=0;i<aMenuLis.length;i++){
			aMenuLis[i].index = i;
			aMenuLis[i].onclick = function(){
				if(this.index != currentLi){
					showContent(this.index);
					//请求数据
					askCourseInfor(this.index);
				}
			}
		}

		function showContent(index){
			if (index != currentLi) {
				aMenuIcon[index].style.display = "block";
				aMenuIcon[currentLi].style.display = "none";
				aMenuContent[index].style.display = "block";
				aMenuContent[currentLi].style.display = "none";
				currentLi = index;
			}
		}
		/*--------- personal infor start ---------*/
		var oPersonalInfor = aMenuContent[0];
		var aLis = oPersonalInfor.getElementsByTagName("li");
		var aTips = getElementsByClass("tip",oPersonalInfor);
		var aProcess = [];
		var aInput = oPersonalInfor.getElementsByTagName("input");
		var oBtnSave = document.getElementById("save-btn");
		var personalAsked = false;
		aInput[0].onkeyup = function(){checkUsername(aInput[0],aTips[0])};
		for(var i=0;i<aInput.length;i++){
			//不可编辑
			aInput[i].setAttribute("disabled",true);
			var oProcess = getElementsByClass("process",aLis[i])[0];
			if(oProcess){
				oProcess.index = i;
				aProcess[i] = oProcess;
				aProcess[i].onclick = function(){
					aInput[this.index].removeAttribute("disabled");
					aInput[this.index].focus();
				}
			}
			
		}
		oBtnSave.onclick = function(){
			if(checkUsername(aInput[0],aTips[0])){
				//不可编辑
				for(var i=0;i<aInput.length;i++){
					aInput[i].setAttribute("disabled",true);
					aTips[i].innerText = "";
				}
				//传递数据到后台
				if(aInput[0].value != userInfor.username){
					console.log(1);
					ajax({
						type:"post",
						url:"/cyl/getUserInfo",
						data:{
							useremail:userInfor.useremail,
							username:aInput[0].value
						},
					});	
				}
			}
		}

		/*--------- personal infor end ---------*/
		/*-------- common start -------*/
		var askIndex = 0;
		var aContentAsked = [false,false,false,false,false];
		function setWrapper(oWrapper,askedInfor){
			if(askIndex == 0){
				var i=0;
				aTopSpan[0].innerText = askedInfor.username;
				aTopSpan[1].innerText = askedInfor.email;
				aInput[0].setAttribute("value",askedInfor.username);
				aInput[1].setAttribute("value",askedInfor.email);
				aInput[2].setAttribute("value","****************");
				userInfor = askedInfor;
			}else{
				console.log(askedInfor);
				oWrapper.innerHTML = "";
				for(var i=0;i<20;i++){
					var course = askedInfor[i];
					console.log(course);
					if(course){
						console.log(course.degree);
						var oCourseCard = createCourseCard();
						oCourseCard.courseCard.href = "course-info.html?courseId="+course.id;
						oCourseCard.courseType.innerText = course.type;
						oCourseCard.courseLevel.innerText = course.degree;
						oCourseCard.courseTitle.innerText = course.coursename;
						oCourseCard.courseDesc.innerText = course.detail;
						oCourseCard.courseInfo.innerText = course.click_nums + "人在学习";
						oCourseCard.coursePrice.innerText = "免费";
						if(!course.price || course.price==0){
							addClass(oCourseCard.coursePrice,"course-card-price-free");
							oCourseCard.coursePrice.innerText = "免费";
						}else{
							oCourseCard.coursePrice.innerText = "￥" + course.price;
						}
						if((i+1)%5 == 0){
							addClass(oCourseCard.wrapper,"last-item");
						}else{
							addClass(oCourseCard.wrapper,"item");
						}
						console.log(oCourseCard.wrapper);
						oWrapper.appendChild(oCourseCard.wrapper);
					}
				}
			}
		}
		function askCourseInfor(index){ 
			if(!aContentAsked[index]){
				askIndex = index;
				showLoading();
				var url,data;
		
				url ="/cyl/getUserInfo";//访问路径
				data = {
					//email:getCookie("useremail"),
					email:"1354322421@qq.com",
					ask_type:index
				};
			
				ajax({
					type:"post",
					url:url,
					data:data,
					success:askInforSuccess,
					fail:askInforFail
				});	
				//setWrapper(aMenuContent[askIndex],{"1":{"id":1,"type":"HTML/CSS","degree":"高级","coursename":"HTML+CSS基础教程","detail":"HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义","click_nums":999,"price":0}});
				//askInforSuccess('{"username":"千宇碎空","useremail":"742230063@qq.com","password":"123456"}');
			}
		}
		function askInforSuccess(response){
			console.log(response);
			var respJson = JSON.parse(response);
			console.log(respJson);
			console.log(userInfor.username);
			hideLoading();
			aContentAsked[askIndex] = true;
			//setWrapper(aMenuContent[askIndex],{username:"千宇碎空",useremail:"742230063@qq.com",password:123456});
			setWrapper(aMenuContent[askIndex],respJson);
		}
		function askInforFail(response){
			console.log("fail");
			showLoadingFail();
		}
		/*-------- common end -------*/
	/*=============== main end ==============*/
	var oLoading = document.getElementById("loading");
	var oLoadingFail = document.getElementById("loading-fail");
	createLoading(oLoading);
	function showLoading(){
		hideLoadingFail();
		oLoading.style.display = "block";
	}
	function hideLoading(){
		oLoading.style.display = "none";
	}
	function showLoadingFail(){
		hideLoading();
		oLoadingFail.style.display = "block";
	}
	function hideLoadingFail(){
		oLoadingFail.style.display = "none";
	}
	function createLoading(box){
		var transY = getStyle(box,"font-size");
		for(var i=0;i<8;i++){
			var span = document.createElement("span");
			addClass(span,"point");
			box.appendChild(span);
			span.style.transform = "rotateZ("+360/8*i+"deg) translateY("+transY+")";
		}
	}
	askCourseInfor(0);